package HLLib.control;

import HLCode.HLClass;
import HLCode.HLClassManager;
import HLCode.HLClassManager_H;
import HLCode.HLObject;
import HLLib.base.HLGraphics;
import HLLib.base.HLGraphics_H;
import HLLib.base.HLString;

public class HLLabel extends HLControl implements HLGraphics_H {
    public HLClass GetClass(HLClassManager classManager) {
        return classManager.GetLibClass(HLClassManager_H.CLASS_GROUP_TYPE_LIB_CONTROL, HLClassManager_H.LIB_CLASS_CONTROL_Label);
    }

    public int GetInt(int index) {
        switch (index) {
        case 0: {
            return textColor;
        }
        case 1: {
            return backColor;
        }
        case 2: {
            return timer;
        }
        case 3: {
            return showCount;
        }
        }
        return 0;
    }

    public void SetInt(int index, int value) {
        switch (index) {
        case 0: {
            textColor = value;
            return;
        }
        case 1: {
            backColor = value;
            return;
        }
        case 2: {
            timer = value;
            return;
        }
        case 3: {
            showCount = value;
            return;
        }
        }
    }

    public HLObject GetObject(int index) {
        return text;
    }

    public void SetObject(int index, HLObject value) {
        text = (HLString) value;
    }

    static final int TYPE_NORMAL = 0;

    static final int TYPE_THROUGH = 1;

    static final int TYPE_SWING = 2;

    byte type;

    public HLString text;

    public int textColor = 0xffffffff;

    public int backColor = 0;

    byte textPosStyle = LEFT_VCENTER;

    byte swingStopTime = 15;

    byte step = 2;

    int offset = 0;

    byte rimSize = 1;

    public int timer;

    public int showCount = 0;

    public void SettingNormal(int rimSize, int textColor, int backColor, int textPosStyle) {
        type = TYPE_NORMAL;

        this.rimSize = (byte) rimSize;
        this.textColor = textColor;
        this.backColor = backColor;
        this.textPosStyle = (byte) textPosStyle;

        timer = 0;
        showCount = 0;
    }

    public void SettingThrough(int rimSize, int textColor, int backColor, int textPosStyle, int step, int startOffsetPercent) {
        type = TYPE_THROUGH;

        this.rimSize = (byte) rimSize;
        this.textColor = textColor;
        this.backColor = backColor;
        this.textPosStyle = (byte) textPosStyle;

        this.step = (byte) step;

        offset = width * startOffsetPercent / 100;

        timer = 0;
        showCount = 0;
    }

    public void SettingSwing(int rimSize, int textColor, int backColor, int textPosStyle, int step, int startOffsetPercent) {
        type = TYPE_SWING;

        this.rimSize = (byte) rimSize;
        this.textColor = textColor;
        this.backColor = backColor;
        this.textPosStyle = (byte) textPosStyle;

        this.step = (byte) step;

        offset = width * startOffsetPercent / 100;

        timer = 0;
        showCount = 0;
    }

    public void SetArea(int rectX, int rectY, int rectWidth, int rectHeight) {
        x = rectX;
        y = rectY;
        width = rectWidth;
        height = rectHeight;
    }

    public void Logic() {
        switch (type) {
        case TYPE_NORMAL: {
            break;
        }
        case TYPE_THROUGH: {
            offset += step;
            if (step > 0) {
                if (offset >= width) {
                    offset = -HLGraphics.StringWidth(text);
                    showCount++;
                }
            } else {
                if (offset <= -HLGraphics.StringWidth(text)) {
                    offset = width;
                    showCount++;
                }
            }
            break;
        }
        case TYPE_SWING: {
            offset += step;
            if (step > 0) {
                if (offset >= rimSize) {
                    step = (byte) -step;
                    showCount++;
                }
            } else {
                if (offset <= width - rimSize - HLGraphics.StringWidth(text)) {
                    step = (byte) -step;
                    showCount++;
                }
            }
            break;
        }
        }

        timer++;
    }

    public void Render(HLGraphics g) {
        g.StoreClip();

        g.ClipRect(x, y, width, height);

        g.FillRectAlpha(x, y, width, height, backColor);

        g.DrawStringAdjustable(text, textColor, 0, x + offset + rimSize, y + rimSize, width - rimSize * 2, height - rimSize * 2, TEXT_STYLE_NORMAL, textPosStyle);

        g.RestoreClip();
    }

    public void Refresh() {
    }

    public void UnLoad() {
    }
}
